<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>资产分类管理</title>
    <link rel="stylesheet" href="../../js/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-select/dist/css/bootstrap-select.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.css">

    <script src="../../js/bower_components/jquery/dist/jquery.min.js"></script>
    <script src="../../js/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../../js/bower_components/bootbox.min.js"></script>
    <script src="../../js/bower_components/bootstrap-select/js/bootstrap-select.js"></script>
    <script src="../../js/bower_components/bootstrap-switch/dist/js/bootstrap-switch.min.js"></script>
    <script src="../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="../../js/bower_components/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>
    <script src="../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.js"></script>
    <script src="../../js/bower_components/jquery-form-validator/form-validator/jquery.form-validator.min.js"></script>
    <script src="../../js/bower_components/moment/min/moment-with-locales.min.js"></script>
   <script>
        $(function(){
				$("#btnAdd").click(function(){
					console.log("模态框的打开方法===1");
					$("#divForm").modal();
					console.log("模态框的打开方法===2");
				})
			//搜索按钮
			$("#btnSearch").click(function(){
				console.log("进入搜索按钮的方法");
				//获取界面当中的控件的值
				var formcode=$("#txtcode").val();
				console.log(formcode);
				var formparentid=$("#selparentid").selectpicker('val');
				console.log(formparentid);
				//整理查询条件
				var user="?";
				if(formcode!=""){
					user+="code="+formcode
					if(formparentid!=""||formparentid!="全部"){
						user+="&parentid="+formparentid
				}
			}
				else if(formparentid!=""){
					if(formparentid!="全部"){
					if(user!=""){
						user+="&parentid="+formparentid
					}else{
						user+="parentid="+formparentid
					}
				}
			}
				
				console.log(user);
				
				//到后端去查询
				
				$.ajax({
					type:"get",
					dataType:"json",
					url:"http://121.37.241.58:8883/logic/baseInfo/category/find"+user,
					success:function(res){
						inittable(res);
					}
				})
			})
			
					initparentid();
					inittable("");
					initparentidForm();
			});

			function initparentid(){
				$("#selparentid").empty;
				$.ajax({
					type:"get",
					url:"http://121.37.241.58:8883/logic/baseInfo/category/parentList",
					dataType:"json",
					success:function(res){
						console.log(res);
						if(!res.flag){
							$.each(res,function(i,n){
								$("#selparentid").append("<option value=\""+n.parentid+"\">"+n.parentid+"</option>")
							});
							$("#selparentid").append("<option value='全部'>全部</option>");
							$("#selparentid").selectpicker('refresh');
						}
					}
				})
			}
			
			
			function initparentidForm(){
				$("#selparentidForm").empty;
				$.ajax({
					type:"get",
					url:"http://121.37.241.58:8883/logic/baseInfo/category/parentList",
					dataType:"json",
					success:function(res){
						console.log(res);
						if(!res.flag){
							$.each(res,function(i,n){
								$("#selparentidForm").append("<option value=\""+n.parentid+"\">"+n.parentid+"</option>")
							});
							$("#selparentidForm").selectpicker('refresh');
						}
					}
				})
			}

			
			function inittable(myData){
				console.log(myData+":默认值")
				$("#tblResult").bootstrapTable("destroy");
				var formcode=$("#txtcode").val();
				var formparentid=$("#selparentid").selectpicker('val');
				if(myData==""){
					if(formcode=="" || formparentid==""){
					console.log("进入无参的方法")
						$("#tblResult").bootstrapTable({
							loadMsg:"正在加载数据....",
							url:"http://121.37.241.58:8883/logic/baseInfo/category/find",
							//data:res,
							sidePagination:'client',
							pageSize:"5",
							Pageinatin: true,
							idField:"id",
							columns:[{
								field:"code",
								title:"分类编号",
								halign:'center'
							},{
								field:"namecn",
								title:"分类名称",
								halign:'center'
							},{
								field:"parentid",
								title:"上级分类",
								halign:'center'
							},{
								field:"comment",
								title:"其他说明",
								halign:'center'
							}]
							
					})
				}else{
					console.log("进入无参的方法")
					
					$("#tblResult").bootstrapTable({
						loadMsg:"正在加载数据....",
						//url:"http://121.37.241.58:8883/logic/baseInfo/category/find",
						data:myData,
						sidePagination:'client',
                        pageSize:"5",
						Pageinatin: true,
						idField:"id",
						columns:[{
							field:"code",
							title:"分类编号",
							halign:'center'
						},{
							field:"namecn",
							title:"分类名称",
							halign:'center'
						},{
							field:"parentid",
							title:"上级分类",
							halign:'center'
						},{
							field:"comment",
							title:"其他说明",
							halign:'center'
						}]
					})
				}
			}else{
				console.log("进入条件查询");
				$("#tblResult").bootstrapTable({
					loadMsg:"正在加载数据....",
					//url:"http://121.37.241.58:8883/logic/baseInfo/category/find",
					data:myData,
					sidePagination:'client',
				    pageSize:"5",
					Pageinatin: true,
					idField:"id",
					columns:[{
						field:"code",
						title:"分类编号",
						halign:'center'
					},{
						field:"namecn",
						title:"分类名称",
						halign:'center'
					},{
						field:"parentid",
						title:"上级分类",
						halign:'center'
					},{
						field:"comment",
						title:"其他说明",
						halign:'center'
					}]
				})
			}
		}
   </script>
</head>
<body>
    <div class="container-flcode">
        <!--查询区域-->
        <div calss="row col-md-10">
            <div id="SearchForm" class="form-inline">
                <div class="input-group">
                    <label for="txtcode" class="control-label">分类编号</label>
                    <input type="text" id="txtcode" />
                </div>
                <div class="input-group">
                    <label class="control-label" for="selparentid">上级分类</label>
                    <select id="selparentid"></select>
                </div>
                <div class="form-group">
                    <button type="button" id="btnSearch" class="btn btn-primary">检索</button>
                </div>
            </div>
        </div>
        <!--功能区域-->
        <div style="margin-top: 5px;" class="form-inline">
            <div id="btnTools">
                <button type="button" id="btnAdd" class="btn btn-success">新增</button>
            </div>
        </div>
        <!--列表区域-->
        <div class="row col-md-10">
            <table id="tblResult"></table>

        </div>
    </div>
    
    <!--模态框的使用-->
    <div class="modal fade" id="divForm" tabindex="-1" parentid="dialog" aria-labelledby="myModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="modalTitle">新增资产</h4>
                </div>
                <div class="modal-body form-inline">
                    <div class="form-group">
                        <label class="control-label" for="txtcodeForm">分类编号</label>
                        <input type="text" id="txtcodeForm" style="width: 200px;" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="txtnamecn">分类名称</label>
                        <input type="text" id="txtnamecn" style="width: 200px;" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="selparentidForm">上级分类</label>
                        <select id="selparentidForm"></select>
                    </div>
                    
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                            <button type="button" class="btn btn-primary">保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</body>
</html>